import 'nprogress/nprogress.css'
import { start, done, configure } from 'nprogress/nprogress'
// import NotFound from "@/views/noFind/"
configure({
  trickleSpeed: 20,
  showSpinner: false
})

function delay (duration) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve()
    }, duration)
  })
}

function getPageComponent (pageCompResolver) {
  return async () => {
    start()
    if (process.env.NODE_ENV === 'development') {
      await delay(2000)
    }
    const comp = await pageCompResolver()
    done()
    return comp
  }
}
const routes = [
  {
    path: '/',
    redirect: '/Home'
  },
  {
    path: '/Home',
    name: '/Home',
    component: () => import('@/views/Home/'),
    redirect: '/Home/index',
    children: [
      {
        path: '/Home/index',
        name: 'index',
        component: getPageComponent(() => import('@/views/Index/')),
        meta: { title: '首页' }
      },
      {
        path: '/Home/About',
        name: 'About',
        component: getPageComponent(() => import('@/views/About/')),
        meta: { title: '关于我' }
      },
      {
        path: '/Home/Blog',
        name: 'Blog',
        component: getPageComponent(() => import('@/views/Blog/')),
        meta: { title: '文章' }
      },
      {
        path: '/Home/cate/:categoryId',
        name: '/Home/cate',
        component: getPageComponent(() => import('@/views/Blog/')),
        meta: { title: '文章' }
      },
      {
        path: '/Home/detail/:id',
        name: 'detail',
        component: getPageComponent(() => import('@/views/Blog/detail/')),
        meta: { title: '文章详情' }
      },
      {
        path: '/Home/project',
        name: 'project',
        component: getPageComponent(() => import('@/views/Project/')),
        meta: { title: '项目&效果' }
      },
      {
        path: '/Home/message',
        name: 'message',
        component: getPageComponent(() => import('@/views/Message/')),
        meta: { title: '留言板' }
      }
    ]
  },
  {
    name: 'notFound',
    path: '*',
    component: () => import('@/views/noFind/')
  }
]
export default routes
